package com.zzh.utils;

import org.apache.commons.codec.digest.DigestUtils;

/**
 * MD5加密工具类
 */
public class MD5 {

    public final static String md5Key = "vivian";

    public static String md5(String text, String key) {
        String encodeStr = DigestUtils.md5Hex(text + key);
        System.out.println("加密后的字符串为：encodeStr = " + encodeStr);
        return encodeStr;
    }

    public static boolean verify(String text, String key, String md5) {
        String md5Text = md5(text, key);
        if (md5Text.equalsIgnoreCase(md5)) {
            System.out.println("验证通过");
            return true;
        }else {
            System.out.println("用户名或者密码错误");
            return false;
        }
    }

    public static void main(String[] args) {
        String zzh = MD5.md5("666", "vivian");
        System.out.println(zzh);

        boolean verify = MD5.verify("666", "vivian", zzh);
        System.out.println("verify = " + verify);
    }
}
